package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.saas.domain.dao.DingRobotManageDao;
import com.xbongbong.saas.domain.entity.DingRobotManageEntity;
import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.saas.enums.mini.DingRobotManagePushEnum;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.xbongbong.saas.model.DingRobotManageModel;

/**
 * @author chenshan
 * @version v1.0
 * @since 2019-08-16 10:50
 */
@Service("dingRobotManageModel")
public class DingRobotManageModelImpl  implements DingRobotManageModel {
	@Resource
	private DingRobotManageDao dingRobotManageDao;

	@Override
	public Integer insert(DingRobotManageEntity entity) {
		long now = DateUtil.getInt();
		entity.setAddTime(now);
		entity.setUpdateTime(now);
		return dingRobotManageDao.insert(entity);
	}

	@Override
	public void insertBatch(List<DingRobotManageEntity> DingRobotManageList) {
		dingRobotManageDao.insertBatch(DingRobotManageList);
	}
    
    
    @Override
    public DingRobotManageEntity findEntity( String openConversationId,String alias,String corpid) {
        Map<String, Object> params = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        params.put("corpid", corpid);
        params.put("alias", alias);
		params.put("openConversationId", openConversationId);
        params.put("del", 0);
        List<DingRobotManageEntity> list = findEntitys(params);
        return list.size()>0 ?  list.get(0):null;
    }

	@Override
	public Integer save(DingRobotManageEntity entity) {
		if ( entity.getId() == null || entity.getId().equals(0L) ) {
			return insert(entity);
		}
		return update(entity);
	}

	@Override
	public Integer update(DingRobotManageEntity entity){
		long now = DateUtil.getInt();
		entity.setUpdateTime(now);
		return dingRobotManageDao.update(entity);
	}

	@Override
	public DingRobotManageEntity getEntity( Long id,String corpid) {
		return dingRobotManageDao.getByKey(id,corpid);
	}

	@Override
	public Integer deleteByIds(List<Long> ids,String corpid) {
		return null;//dingRobotManageDao.deleteByIds(ids,corpid);
	}

	@Override
	public List findEntitys(Map<String, Object> param) {
		return dingRobotManageDao.findEntitys(param);
	}

	@Override
	public Integer getEntitysCount(Map<String, Object> param) {
		return dingRobotManageDao.getEntitysCount(param);
	}
    
    /**
     * Description: 查询符合条件的数据（无子表单数据）
     *
     * @param param
     * @return java.util.List<T>
     * @throws
     * @author 魏荣杰
     * @date 2020/10/13 16:07
     * @since
     */
    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }
    
    @Override
	public DingRobotManageEntity getByAlias( String alias,Long bundleId) {
		return dingRobotManageDao.getByAlias(alias,bundleId);
	}
	
	@Override
	public Integer deleteByOpenConversationId(String openConversationId, String corpid) {
		return dingRobotManageDao.deleteByOpenConversationId(openConversationId,corpid);
	}
}